﻿#include <string>
#include "StdAfx.h"
#include "MioPath.h"
#include "MioReader.h"

using namespace mio;
using std::string;

#if _IPHONE_

TEST(PathTest, appPath)
{
	//존재하지 않는 파일은 빈 문자열
	std::string p1 = path::appPath("asset/asd", "txt");
	std::string p2 = path::appPath("asset/asd.txt");
	string file = "asset/asd.txt";
	string p3 = path::appPath(file);
	EXPECT_EQ(p1, p2);
	EXPECT_EQ(p1, p3);
	EXPECT_STREQ("", p1.c_str());

	//존재하냐느 파일 기준으로 재확인
	p1 = path::appPath("asset/books", "xml");
	p2 = path::appPath("asset/books.xml");
	file = "asset/books.xml";
	p3 = path::appPath(file);
	EXPECT_EQ(p1, p2);
	EXPECT_EQ(p1, p3);
}

TEST(PathTest, docPath)
{
	string p1 = path::docPath("asset/asd", "txt");
	string p2 = path::docPath("asset/asd.txt");
	string file = "asset/asd.txt";
	string p3 = path::docPath(file);
	EXPECT_EQ(p1, p2);
	EXPECT_EQ(p1, p3);
}

TEST(PathTest, isFileExist)
{
	//app path test
	string p1 = path::appPath("asset/books.xml");
	EXPECT_EQ(true, path::isFileExist(p1));
	
	string p2 = path::appPath("asset/fdsjkl.xml");
	EXPECT_EQ(false, path::isFileExist(p2));
	
	string p3 = path::docPath("asset/asd.txt");
	EXPECT_EQ(false, path::isFileExist(p3));
	
	//doc path에 임시파일 생성
	string p4 = path::docPath("test.txt");
	FILE *f = fopen(p4.c_str(), "wb");
	fprintf(f, "test");
	fclose(f);
	EXPECT_EQ(true, path::isFileExist(p4));
}
/*
TEST(Path, filesize)
{
	string p1 = path::appPath("asset/books.xml");
	EXPECT_EQ(4406, File::filesize(p1));
}

TEST(Path, copy)

{
	string p1 = path::appPath("asset/books.xml");
	string p2 = path::docPath("copy_tmp");
	File::copy(p1, p2);
	EXPECT_EQ(File::filesize(p1), File::filesize(p2));
	
	//읽어서 내용 확인
	string content1 = mio::reader::read(p1);
	string content2 = mio::reader::read(p2);
	EXPECT_TRUE(content1 == content2);
}
*/
#endif